<?php $this -> load -> view('header'); ?>
<!-- BEGIN CONTAINER -->
<div class="page-container row-fluid">
	<?php //$this->load->view('sidebar');?>
	<!-- BEGIN PAGE -->
	<div class="page-content">
		<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
		<div id="portlet-config" class="modal hide">
			<div class="modal-header">
				<button data-dismiss="modal" class="close" type="button"></button>
				<h3>portlet Settings</h3>
			</div>
			<div class="modal-body">
				<p>
					Here will be a configuration form
				</p>
			</div>
		</div>
		<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
		<!-- BEGIN PAGE CONTAINER-->
		<div class="container-fluid">
			<!-- BEGIN PAGE HEADER-->
			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->
				<!--	<h3 class="page-title"> Daftar Laporan</h3>
					<?php $this -> load -> view('breadcrumb'); ?> -->
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<!--<div class="row-fluid">
				<div class="span12">
					
				</div>
			</div>-->
			<div class="row-fluid">
						<div class="span3 responsive" data-tablet="span6" data-desktop="span3">
							
						</div>
						<div class="span3 responsive" data-tablet="span6" data-desktop="span3">
							<div class="dashboard-stat green">
								<div class="visual">
									<i class="icon-bar-chart"></i>
								</div>
								<div class="details">
									<div class="number" id="finalNumber"></div>
									<div class="desc">Jumlah Laporan Final</div>
								</div>
								<a class="more" href="#">
								View more <i class="m-icon-swapright m-icon-white"></i>
								</a>						
							</div>
						</div>
						<div class="span3 responsive" data-tablet="span6  fix-offset" data-desktop="span3">
							<div class="dashboard-stat blue">
								<div class="visual">
									<i class="icon-bookmark"></i>
								</div>
								<div class="details">
									<div class="number">
										<?php echo $pBerkas['count'];?>
									</div>
									<div class="desc">									
										Jumlah Laporan Terkirim
									</div>
								</div>
								<a class="more" href="#">
								View more <i class="m-icon-swapright m-icon-white"></i>
								</a>						
							</div>
						</div>
						<div class="span3 responsive" data-tablet="span6" data-desktop="span3">
							
						</div>
					</div>
					<!-- END DASHBOARD STATS -->
					
					<div class="clearfix"></div>
					<div class="row-fluid">
						<div class="span6">
							<!-- BEGIN PORTLET-->
							<div class="portlet solid bordered light-grey">
								<div class="portlet-title">
									<h4><i class="icon-bar-chart"></i>Laporan Sudah Final</h4>
									<!--<div class="tools">
										<div class="btn-group pull-right" data-toggle="buttons-radio">
											<a href="javascript:;" class="btn mini">Users</a>
											<a href="javascript:;" class="btn mini active">Feedbacks</a>
										</div>
									</div>-->
								</div>
								<div class="portlet-body">
									<div id="berkas_success_loading">
										<img src="<?php echo base_url()?>assets/img/loading.gif" alt="loading" />
									</div>
									<div id="berkas_success_content" class="hide">
										<table class="table-striped table-bordered table-advance table-hover" id="finalBerkasTable">	
										<thead>
											<tr>
												<!--<th align="center">No</th>-->
												<th align="center">Kode Laporan</th>
												<th class="center">Nama Perpustakaan</th>
												<th class="center">Jenis Laporan</th>
												<!--<th>No Indikator</th>-->
												<th class="center">Tanggal Pelaporan</th>
												<!--<th>Last Comment</th>-->
												<th class="center">Tanggal Selesai</th> 
												<!--<th class="center">Tindakan</th>-->
											</tr>
										</thead>
										<tbody>
											
										</tbody>
										</table>
										<div class="row-fluid" id="pagingSentBerkas">
											
										</div>
									</div>
								</div>
							</div>
							<!-- END PORTLET-->
						</div>
						<div class="span6">
							<div class="portlet solid bordered light-grey">
								<div class="portlet-title">
									<h4><i class="icon-bar-chart"></i>Laporan Terkirim</h4>
								</div>	
								<div class="portlet-body">									
									<table class="table-striped table-bordered table-advance table-hover">	
										<thead>
											<tr>
												<!--<th align="center">No</th>-->
												<th align="center">Kode Laporan</th>
												<th class="center">Nama Perpustakaan</th>
												<th class="center">Jenis Laporan</th>
												<!--<th>No Indikator</th>-->
												<th class="center">Tanggal Pelaporan</th>
												<!--<th>Last Comment</th>-->
												<th class="center">Posisi</th> 
												<!--<th class="center">Tindakan</th>-->
											</tr>
										</thead>
										
										<tbody>
										<?php
											$i=1; 
											foreach ($pBerkas['data'] as $berkas){ ?>
											<tr >
												<!--<td><?php echo $i;?></td>-->
												<td style="text-align: center;"><?php echo $berkas->getId();?></td>
												<td style="text-align: left;"><?php echo $berkas->getPerpustakaan()->getNama();?></td>
												<td style="text-align: left;"><?php echo $berkas->getTipe()->getNama();
													
													?></td>
												
												<td class="center"><?php echo ($berkas->getStartDate() != NULL) ? $berkas->getStartDate()->format('d-m-Y') : "";?></td>
												<td>
													<?php 
														  echo '<span class="label label-success">'.$berkas->getInbox()->getProcedureStep()->getId() . " - " .$berkas->getInbox()->getProcedureStep()->getNama().'</span>'; 
														  		
													?></td>
												
										
											</tr>		
										<?php	$i++;} ?>
										</tbody>
									</table>
									<div class="row-fluid">
										<?php $this->load->view('paging', $pBerkas);?>
									</div>
								</div>	
							</div>	
						</div>
					</div>	
			<!-- END PAGE CONTENT -->
		</div>
		<!-- END PAGE CONTAINER-->
	</div>
	<!-- END PAGE -->
</div>
<!-- END CONTAINER -->
<?php $this->load->view('footer')?>
<script>
	$(document).ready(function() {
		findFinalBerkas = function(idxPage){
			if (idxPage == 0 || idxPage == null || typeof idxPage == 'undefined'){
				idxPage = 1;
			} 
			$.ajax({
				  url: "<?php echo base_url()?>/inbox/findFinalBerkasByUserLogin",
				  success: function(data){
				  	  rebuildFinalBerkasTableHandler(data, idxPage);
				  },
				  type:"POST",
				  data: { page: idxPage},
				  dataType: "json"
			});
		}
		
		rebuildFinalBerkasTableHandler = function(data, selectedPage){
			//$("#finalBerkasTable").find("tr:gt(0)").remove();
			var html = '';
			$.map(data.resultData.data, function(item) {
				html += '<tr>'
					 + '<td>' + item.id + '</td>'
					 + '<td>' + item.namaPerpustakaan+ '</td>'
					 + '<td>' + item.jenisLaporan + '</td>'
					 + '<td>' + item.tglLaporan + '</td>'
					 + '<td>' + item.tglSelesai + '</td>'
					 + '</tr>';
			}); 
			$('#finalBerkasTable tbody').after(html);
			$('#finalNumber').html(data.resultData.count);
			var countData = data.resultData.count;
			var part2 = '';
			var indexAndCount = data.resultData.indexAndCount;
			var numpage = Math.ceil(countData/10);
			//var	activePage = ceil((indexAndCount[0] + 1)/ 10);
			var activePage = selectedPage; 
				if ((activePage * indexAndCount[1]) >= countData){
					part2 = countData;
				} else {
					part2 = activePage * indexAndCount[1];
				}  
			
			var info = '';
			if (countData > 0)
				info = 'Showing '+indexAndCount[0]+' to ' + part2 + ' of ' + countData + ' entries'; 
			else 
				info = 'Showing 0 to ' + part2 + ' of ' + countData + ' entries';
				
			var paging = '<div class="span6"><div class="dataTables_info" id="sample_2_info">'
												+ info + '</div>'
												+'</div>';
			var paging2= '<div class="span6">' + 
			  				'<div class="dataTables_paginate paging_bootstrap pagination">';
			if (selectedPage == 1){
				paging2 = paging2 + '<ul><li class="prev disabled">'
							 +'<a href="#">← Prev</a>'
						   +'</li>';	
			} else {
				paging2 = paging2 + '<ul><li class="prev">'
							 +'<a href="#" id="linkPagePrev" onClick="findFinalBerkas('+(selectedPage-1)+')">← Prev</a>'+
						  '</li>';
			}
			
			for (var i=1;i<=numpage;i++){
				if (i==activePage){
						paging2 = paging2  +  '<li class="active">';
				} else {
						paging2 = paging2 + '<li>';	
				}
				paging2 = paging2 + '	<a href="#" id="linkPage'+i+'" onClick="findFinalBerkas('+i+')">'+i+'</a>'
								 +'</li>';		
			}									
													
			if (activePage == numpage){
					paging2 = paging2 + '<li class="next disabled">'
							+'<a href="#">Next → </a>'
						  +'</li>';	
			} else {
					paging2 = paging2 + '<li class="next">'
							+'<a href="#" onClick="findFinalBerkas('+(activePage+1)+')">Next → </a>'
						  +'</li>';
			}										
													
			paging = paging+ paging2 + '</div>' +'</div>';
			$('#pagingSentBerkas').html(paging);
		}
		
		findFinalBerkas();
		$('#berkas_success_loading').hide();
		$('#berkas_success_content').show();
		
	});
	
</script>